package com.liu.algorithm.strategy;

import java.util.Comparator;

/**
 * @author LIU
 * @version 1.0
 * @description: TODO
 * @date 2022/8/25 11:05
 */
public class Sorter2<T> {
    public  void  sort (T[] arr, Comparator<T> comparator){
        for (int i = 0; i < arr.length ; i++) {
            int minValueIndex = i;
            for (int j = i+1; j < arr.length ; j++) {
               minValueIndex = comparator.compare(arr[j],arr[minValueIndex])== 1? minValueIndex :j;
            }
            swap(arr,i,minValueIndex);
        }
    }

    public  void swap(T[] arr,int i,int j){
        T temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }
}
